﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;

namespace DtuService
{
    //定义处理程序委托
    public delegate bool ConsoleCtrlDelegate(int dwCtrlType);

    class Win32Helper
    {
        [DllImport("User32.dll", EntryPoint = "FindWindow")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", EntryPoint = "FindWindowEx")]   //找子窗体   
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("User32.dll", EntryPoint = "SendMessage")]   //用于发送信息给窗体   
        public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);

        [DllImport("User32.dll", EntryPoint = "ShowWindow")]   //
        public static extern bool ShowWindow(IntPtr hWnd, int type);

        [DllImport("User32.dll")]
        public static extern bool ShowWindowAsync(System.IntPtr hWnd, int cmdShow);
        [DllImport("User32.dll")]
        public static extern bool SetForegroundWindow(System.IntPtr hWnd);
        /// <summary>
        /// 计时器回调函数，在这里处理计时时间是否到达的判断以及要做的事情；
        /// </summary>
        /// <param name="obj"></param>
        public static void workOvertimeTimerCallback(object obj)
        {
            DateTime dt = DateTime.Now;
            if (dt.Hour == 16 && dt.Minute > 0)
            {
                Console.WriteLine("ok");
            }
        }
        // DialogResult dr = MessageBox.Show("任务还没有完成，确认要退出吗？","提示",  MessageBoxButtons.YesNo, MessageBoxIcon.Information);
        //if (dr == DialogResult.Yes)
        //    return true;
        //else
        //    return false;
        public const int CTRL_CLOSE_EVENT = 2;

        //导入SetCtrlHandler API
        [DllImport("kernel32.dll")]
        public static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add);
    }
}
